<?php 

class Slide_model extends CI_Model{
	public function __construct() {
        parent::__construct();
		$this->load->library('upload');
    }
	
	function create($data){
		$config = $this->upload->data('slide_image');
		$data = array(
					'slide_name' => $this->input->post('slide_name'),
					'slide_image' => ''.$config['file_name'],
					'slide_description' => $this->input->post('slide_description'),
					'status' => $this->input->post('status')
				);
		$this->db_front->insert('slide',$data);
	}
	
	function getAll($page='', $limit=''){
		if(!empty($limit))
		$this->db_front->limit($limit,$page);
		
		$query = $this->db_front->get('slide');
		
		if($query -> num_rows() > 0){
			foreach ($query -> result() as $rows){
				$data[] = $rows;	
			}	
			return $data;
		}	
	}
	
	function get_slide_by_id($slide_id){
		$this->db_front->where('slide_id', $slide_id);
		$this->db_front->from('slide');
		$query = $this->db_front->get();
		return $query->row_array();		
		}
	
	function update($slide_id){
		$config = $this->upload->data('slide_image');
		if(!empty($config['file_name'])){
			$data = array(
					'slide_name' => $this->input->post('slide_name'),
					'slide_image' => ''.$config['file_name'],
					'slide_description' => $this->input->post('slide_description'),
					'status' => $this->input->post('status')
				);
        $this->db_front->where('slide_id', $slide_id);
        $this->db_front->update('slide', $data);
		}else{
			$data = array(
					'slide_name' => $this->input->post('slide_name'),
					'slide_description' => $this->input->post('slide_description'),
					'status' => $this->input->post('status')
					);
			$this->db_front->where('slide_id', $slide_id);
			$this->db_front->update('slide', $data);
		}
		
    }
	
	function select($slide_id){
        return $this->db_front->get_where('slide', array('slide_id'=>$slide_id))->row();
    }
	
	function delete($slide_id){
        $this->db_front->delete('slide', array('slide_id'=>$slide_id));
    }
}
?>